//
// Created by Lenovo on 2024/3/14.
//
#include<bits/stdc++.h>
using namespace std;

class Solution {
public:



    //查
    int find(int x,vector<int>& p){
        if(p[x]==x) return x;
        else return p[x]=find(p[x],p);
    }


    bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {
        vector<int> p=vector<int>(n);
        for(int i=0;i<n;i++) p[i]=i;
        for(int i=0;i<edges.size();i++){
            int pu=find(edges[i][0],p);
            int pv=find(edges[i][1],p);
            if(pu!=pv){
                p[pu]=pv;
            }
        }
        if(find(source,p)== find(destination,p))
            return true;
        else
            return false;
    }
};